//
//  Enums.swift
//  ZZJSONModel
//
//  Created by 陈钟 on 2025/5/26.
//


import Cocoa


enum Language: String{
    case swift = "Swift"
    case oc = "Object-C"
    case dart = "Dart"
    
    var tag: Int{
        switch self {
            case .swift:
                return 1
            case .oc:
                return 2 
            case .dart:
                return 3
        }
    }
    
    init(tag: Int) {
        switch tag {
            case 1:
                self = .swift
            case 2:
                self = .oc
            case 3:
                self = .dart
            default:
                self = .swift
        }
    }
    
}

enum ObjType {
    case dic
    case array
    
    case string
    case int
    case double
    case float
    case bool
    
    case null
    
    case anyobj
    
    func unit(with language: Language) -> String{
        switch language {
            case .swift:
                return self.unit
            case .oc:
                return self.ocUnit
            case .dart:
                return self.dartUnit
        }
    }
    
    private  var unit: String{
        switch self{
            case .dic: return "[String: Any]"
            case .array : return "[]"
                
            case .string: return "String"
            case .int: return "Int"
            case .double: return "Double"
            case .float: return "Float"
                
            case .null: return "Any"
                
            case .anyobj: return "Any"
                
            case .bool: return "Bool"
        }
    }
    
    private var ocUnit: String{
        switch self{
            case .dic: return "NSDictionary"
            case .array : return "NSArray"
                
            case .string: return "NSString"
            case .int: return "NSInteger"
            case .double: return "double"
            case .float: return "CGFloat"
                
            case .null: return "NSObject"
                
            case .anyobj: return "NSObject"
                
            case .bool: return "BOOL"
        }
    }
    
    private  var dartUnit: String{
        switch self{
            case .dic: return "Map<String, dynamic>"
//            case .dic: return "{String: Any}"
            case .array : return "List"
                
            case .string: return "String"
            case .int: return "int"
            case .double: return "double"
            case .float: return "double"
                
            case .null: return "dynamic"
                
            case .anyobj: return "dynamic"
                
            case .bool: return "bool"
        }
    }
    
    var normalValue: String{
        switch self{
            case .dic: return "[:]"
            case .array : return "[]"
                
            case .string: return "\"\""
            case .int: return "0"
            case .double: return "0"
            case .float: return "0"
                
            case .null: return ""
                
            case .anyobj: return ""
                
            case .bool: return "false"
        }
    }
    
    init(obj : Any, userString: Bool = false)  {
        var type: ObjType = .anyobj
        if userString {
            if let _ =  obj as? [AnyHashable: Any] {
                type = .dic
            }
            if let _ = obj as? [Any] {
                type = .array
            }
            type = .string
            self = type
            return
        }
        if let _ = obj as? String{
            let objValue = obj as? String
            if objValue?.lowercased() == "null"{
                type = .null
            }else {
                type = .string
            }
        }
        if let _ = obj as? Bool{
            type = .bool
        }
        if let _ = obj as? Int {
            type = .int
        }
        if let _ = obj as? Double {
            type = .double
        }
        if let _ = obj as? Float {
            type = .float
        }
        if let _ = obj as? NSNull {
            type = .null
        }
        if let _ = obj as? [AnyHashable: Any] {
            type = .dic
        }
        if let _ = obj as? [Any] {
            type = .array
        }
        self = type
    }
}
